2 Copyright (C) 2024 Rubén Beltrán del Río
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see https://map.tranquil.systems.
19 struct MapBlockers: View {
22 let vertexSize: CGSize
23 let blockers: [Blocker]
25 let cornerSize = CGSize(width: 2.0, height: 2.0)
28 ForEach(blockers, id: \.id) { vertex in
33 x: w(vertex.position.x) + 3 * vertexSize.width,
34 y: h(vertex.position.y) - vertexSize.height * 2 / 3),
35 size: CGSize(width: vertexSize.width / 2, height: vertexSize.height * 2)
36 ), cornerSize: cornerSize)
37 }.fill(Color.map.blockerColor)
41 func h(_ dimension: CGFloat) -> CGFloat {
42 max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
45 func w(_ dimension: CGFloat) -> CGFloat {
46 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
52 mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0),
54 Blocker(id: 0, position: CGPoint(x: 50.0, y: 50.0)),
55 Blocker(id: 1, position: CGPoint(x: 10.0, y: 20.0)),